<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="任务单号">
              <p-input placeholder="请输入任务单号" v-model="queryParam.taskBillno"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</p-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <p-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </p-col>
        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button @click="add" type="primary" icon="plus">新增</p-button>

      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
        <p-button
          v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )"
          :key=" 'cgbtn'+index "
          @click="cgButtonJsHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
        <p-button
          v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
          :key=" 'cgbtn'+index "
          @click="cgButtonActionHandler(item.buttonCode)"
          type="primary"
          :icon="item.buttonIcon"
        >{{ item.buttonName }}</p-button>
      </template>

      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="fieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>

      <p-dropdown v-for="(item,index) in groupTag" :key="index">
        <p-button>
          {{item.name}}
          <p-icon type="down" />
        </p-button>
        <p-menu slot="overlay">
          <template v-for="(items,indexs) in item.data">
            <p-menu-item
              v-if=" items.optType=='js' "
              :key="indexs"
              @click="cgButtonJsHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
            <p-menu-item
              v-else-if=" items.optType=='action' "
              :key="indexs"
              @click="cgButtonActionHandler(items.buttonCode)"
            >
              <p-icon :type="items.buttonIcon" />
              {{items.buttonName}}
            </p-menu-item>
          </template>
        </p-menu>
      </p-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="poros-alert poros-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle poros-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="handleExportXls('质量问题改善单')">
            <p-icon type="download" />导出
          </a>
          <p-divider type="vertical" />
          <p-upload
            name="file"
            :showUploadList="false"
            :multiple="false"
            :headers="tokenHeader"
            :action="importExcelUrl"
            @change="handleImportExcel"
          >
            <a>
              <p-icon type="import" />导入
            </a>
          </p-upload>
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新
          </a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group
                @change="onColSettingsChange"
                v-model="settingColumns"
                :defaultValue="settingColumns"
              >
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列
            </a>
          </p-popover>
        </span>
      </div>

      <p-table
        ref="table"
        size="small"
        bordered
        rowKey="id"
        :scroll="{ x: 1450 }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
      >
        <div
          slot="filterDropdown"
          slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px"
        >
          <p-input
            v-ant-ref="c => (searchInput = c)"
            :placeholder="`请输入 ${column.title}`"
            :value="selectedKeys[0]"
            style="width: 188px; margin-bottom: 8px; display: block;"
            @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
          />
          <p-button
            type="primary"
            icon="search"
            size="small"
            style="width: 90px; margin-right: 8px"
            @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">取消</p-button>
        </div>
        <div
          slot="filterDropdownDate"
          slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px"
        >
          <p-form-item :label="` ${column.title}`">
            <j-date
              :show-time="true"
              date-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择开始时间"
              class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_begin`]"
            ></j-date>
            <span class="query-group-split-cust"></span>
            <j-date
              :show-time="true"
              date-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择结束时间"
              class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_end`]"
            ></j-date>
          </p-form-item>
          <p-button
            type="primary"
            icon="search"
            size="small"
            style="width: 90px; margin-right: 8px"
            @click="() => handleSearchDate(selectedKeys, confirm, column.dataIndex)"
          >确认</p-button>
          <p-button
            size="small"
            style="width: 90px"
            @click="() => handleResetDate(clearFilters,`${column.dataIndex}_begin`,`${column.dataIndex}_end`)"
          >取消</p-button>
        </div>
        <p-icon
          slot="filterIcon"
          slot-scope="filtered"
          type="search"
          :style="{ color: filtered ? '#108ee9' : undefined }"
        />
        <template slot="taskBillno" slot-scope="text,record">
          <span
            v-if=" record.callbackPath.length > 0 "
          >
            <a @click="handleProcess(record)" style="color:red;">{{text}}</a>
          </span>
          <span v-else>
            <a @click="handleProcess(record)">{{text}}</a>
          </span>
        </template>
        <template slot="processingCycle" slot-scope="text,record">{{getProcessingCycle(record)}}</template>
        <template slot="replyOverdue" slot-scope="text,record">{{getReplyOverdue(record)}}</template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >下载</p-button>
        </template>
        <template slot="taskStatus" slot-scope="text,record">
          <div v-if="!text">/</div>
          <p-tag v-else-if="record.taskStatus ==1" color="blue">
            <p-icon type="issues-close" />待回复措施
          </p-tag>
          <p-tag v-else-if="record.taskStatus==2" color="#2db7f5">
            <p-icon type="clock-circle" />待审核
          </p-tag>
          <p-tag v-else-if="record.taskStatus==3" color="purple">
            <p-icon type="check-circle" />改善中
          </p-tag>
          <p-tag v-else-if="record.taskStatus==4">
            <p-icon type="close-circle" />待验证
          </p-tag>
          <p-tag v-else-if="record.taskStatus==5" color="green">
            <p-icon type="check-circle" />关闭
          </p-tag>
          <p-tag v-else-if="record.taskStatus==6" color="red">
            <p-icon type="close-circle" />驳回
          </p-tag>
        </template>

        <span slot="action" slot-scope="text, record">
          <span v-if=" record.callbackPath.length > 0 ">
            <a @click="handleProcess(record)" style="color:red;">处理</a>
          </span>
          <span v-else>
            <a @click="handleProcess(record)">详情</a>
          </span>
        </span>
      </p-table>
    </div>
    <!-- table区域-end -->

    <!-- 弹出窗 -->
    <Fx-compontens-modal
      @ok="modalFormOk"
      ref="modalCompon"
      :getList="queryInfo"
      :title="title"
      :dictOptions="dictOptions"
    ></Fx-compontens-modal>
  </p-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { api } from '@/api/manage'
import process from '@/api/process'
import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
import { filterObj } from '@/utils/util'
import MesQcQualityImproveTask_1Modal from './modules/MesQcQualityImproveTask_1Process.vue'
import dayjs from 'dayjs'
import Vue from 'vue'
import {
  initDictOptions,
  filterMultiDictText,
} from '@/components/dict/JDictSelectUtil'
import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
import { postAction, getAction, deleteAction } from '@/api/manage'
import FxCompontensModal from '@/components/jeecgbiz/FxCompontensModal'

//高级查询modal需要参数
const superQueryFieldList = [
  {
    value: 'createTime',
    text: '创建日期',
    type: 'Date',
  },
  {
    value: 'taskBillno',
    text: '任务单号',
    type: 'String',
  },
  {
    value: 'sourceType',
    text: '来源类型',
    type: 'select',
    dictCode: 'mes_quality_improve_task_source_type',
  },
  {
    value: 'introducerDepartment',
    text: '提出人部门',
    type: 'String',
  },
  {
    value: 'questionExplain',
    text: '问题描述',
    type: 'String',
  },
  {
    value: 'dutyDepartment',
    text: '责任部门',
    type: 'String',
  },
  {
    value: 'replyDate',
    text: '回复日期',
    type: 'Date',
  },
  {
    value: 'replyOverdue',
    text: '回复超期天数',
    type: 'int',
  },
  {
    value: 'processingCycle',
    text: '处理周期',
    type: 'int',
  },
  {
    value: 'taskStatus',
    text: '任务状态',
    type: 'select',
    dictCode: 'mes_task_status',
  },
  {
    value: 'annexUrl',
    text: '附件url',
    type: 'String',
  },
  {
    value: 'introducer',
    text: '提出人',
    type: 'String',
  },
  {
    value: 'mcode',
    text: '产品编号',
    type: 'String',
  },
  {
    value: 'mname',
    text: '产品名称',
    type: 'String',
  },
  {
    value: 'process2',
    text: '二级工序',
    type: 'String',
  },
  {
    value: 'nrpReplytime',
    text: '要求报告回复时间',
    type: 'Date',
  },
  {
    value: 'handler',
    text: '处理人',
    type: 'String',
  },
  {
    value: 'handleTime',
    text: '处理时间',
    type: 'Date',
  },
  {
    value: 'inspectBillno',
    text: '检验单号',
    type: 'String',
  },
  {
    value: 'creportUrl',
    text: '改善报告附件',
    type: 'String',
  },
  {
    value: 'cmeasureExplain',
    text: '改善措施简述',
    type: 'String',
  },
  {
    value: 'measureYeTime',
    text: '措施预计完成时间',
    type: 'Date',
  },
  {
    value: 'operation',
    text: '操作',
    type: 'int',
  },
  {
    value: 'currentHandler',
    text: '当前处理人',
    type: 'String',
  },
  {
    value: 'reviewTime',
    text: '审核时间',
    type: 'Date',
  },
  {
    value: 'isCloseFile',
    text: '是否可结案',
    type: 'select',
    dictCode: '',
  },
  {
    value: 'mefConditionRemark',
    text: '措施完成情况说明',
    type: 'String',
  },
  {
    value: 'checkTime',
    text: '验证时间',
    type: 'Date',
  },
  {
    value: 'processInstanceId',
    text: '流程实例ID',
    type: 'String',
  },
  {
    value: 'callbackPath',
    text: '地址',
    type: 'String',
  },
]

export default {
  name: 'MesQcQualityImproveTask_1List',
  mixins: [JeecgListMixin],
  components: {
    JSuperQuery,
    FxCompontensModal,
    MesQcQualityImproveTask_1Modal,
  },
  data() {
    return {
      fieldList: superQueryFieldList,
      superQueryFlag: false,
      superQueryParams: '',
      description: '质量问题改善单管理页面',
      cgButtonLinkList: [],
      title: '', //存表名
      EnhanceJS: '',
      cgButtonList: [],
      groupTag: [],
      queryInfo: [],
      taskList: [],
      code: '',
      // 表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义
      defColumns: [
        {
          title: "序号",
          dataIndex: '',
          key: 'rowIndex',
          width: 30,
          fixed: 'left',
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '任务单号',
          align: 'center',
          dataIndex: 'taskBillno',
          width: 150,
          fixed: 'left',
          scopedSlots: { customRender: 'taskBillno' },
          sorter: (a, b) => a.taskBillno - b.taskBillno,
        },
        {
          title: '来源类型',
          align: 'center',
          dataIndex: 'sourceType_dictText',
          filters: this.getControl('mes_quality_improve_task_source_type'),
          sorter: (a, b) => a.sourceType - b.sourceType,
        },
         {
          title: '提出人',
          align: 'center',
          dataIndex: 'introducer_dictText',
          sorter: (a, b) => a.dintroducer - b.introducer,
        },
        {
          title: '提出人部门',
          align: 'center',
          dataIndex: 'introducerDepartment_dictText',
          sorter: (a, b) => a.introducerDepartment - b.introducerDepartment,
        },
        {
          title: '问题描述',
          align: 'center',
          dataIndex: 'questionExplain',
          width: 200,
        },
      
        {
          title: '责任部门',
          align: 'center',
          dataIndex: 'dutyDepartment_dictText',
          sorter: (a, b) => a.dutyDepartment - b.dutyDepartment,
        },
        {
          title: '处理人',
          align: 'center',
          dataIndex: 'handler_dictText',
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'customRender',
          },
          sorter: (a, b) => a.handler - b.handler,
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (createTime) {
            return dayjs(createTime).format('YYYY-MM-DD')
          },
          sorter: (a, b) => a.createTime - b.createTime,
        },
        {
          title: '要求回复日期',
          align: 'center',
          dataIndex: 'nrpReplytime',
        },
        {
          title: '实际回复日期',
          align: 'center',
          dataIndex: 'reviewTime',
        },
        {
          title: '回复超期天数',
          align: 'center',
          dataIndex: 'replyOverdue',
          scopedSlots: { customRender: 'replyOverdue' },
        },
        {
          title: '处理周期',
          align: 'center',
          dataIndex: 'processingCycle',
          scopedSlots: { customRender: 'processingCycle' },
        },
         {
          title: '改善报告附件',
          align: 'center',
          dataIndex: 'creportUrl',
          scopedSlots: { customRender: 'fileSlot' },
        }, 

        {
          title: '结案报告附件',
          align: 'center',
          dataIndex: 'annexUrl',
          scopedSlots: { customRender: 'fileSlot' },
        },
        {
          title: '任务状态',
          align: 'center',
          dataIndex: 'taskStatus_dictText',
          width: 120,
          fixed: 'right',
          scopedSlots: { customRender: 'taskStatus' },
          filters: this.getControl('mes_task_status'),
          sorter: (a, b) => a.taskStatus - b.taskStatus,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 60,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/mes-quality/mesQcQualityImproveTask_1/list',
        delete: '/mes-quality/mesQcQualityImproveTask_1/delete',
        deleteBatch: '/mes-quality/mesQcQualityImproveTask_1/deleteBatch',
        exportXlsUrl: '/mes-quality/mesQcQualityImproveTask_1/exportXls',
        importExcelUrl: '/mes-quality/mesQcQualityImproveTask_1/importExcel',
        getColumns: '/mes-quality/online/cgform/api/getColumns/',
        buttonAction: '/mes-quality/online/cgform/api/doButton',
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${api.test}${this.url.importExcelUrl}`
    },
    getWidth: function () {
      if (this.defColumns.length > 14) {
        return { width: '500px' }
      }
    },
    tableScroll: function () {
      if (this.columns.length > 13) {
        return { x: this.columns.length * 150 - 450 }
      }
    },
  },

  created() {
    this.initButtonList()
    this.initColumns()
  },
  mounted() {
    //this.getAssigneeTaskList()
  },
  updated() {
    //this.getAssigneeTaskList()
  },
  methods: {
    add() {
      this.$router.replace(
        '/work/mesQualityManagement/modules/MesQcQualityImproveTask_1Process?action=create&processDefinitionKey=MQImp'
      )
    },
    //确定按钮
    handleSearch(selectedKeys, confirm, dataIndex) {
      confirm()
      this.searchText = selectedKeys[0]
      this.searchedColumn = dataIndex
    },
    //取消按钮
    handleReset(clearFilters) {
      clearFilters()
      this.searchText = ''
    },
    //确定时间
    handleSearchDate(selectedKeys, confirm, dataIndex) {
      confirm()
      this.searchText = selectedKeys[0]
      this.searchedColumn = dataIndex
      this.searchQuery()
    },
    // 清除时间
    handleResetDate(clearFilters, begin, end) {
      if (this.queryParam[begin] || this.queryParam[end]) {
        this.queryParam[begin] = ''
        this.queryParam[end] = ''
        clearFilters()
        this.searchText = ''
        this.searchQuery()
      } else {
        clearFilters()
        this.searchText = ''
      }
    },

    getKey() {
      const dataItem = []
      setTimeout(() => {
        this.columns.forEach((item) => {
          dataItem.push({ text: item.title, value: item.dataIndex })
        })
      }, 100)
      return dataItem
    },
    getControl(dic) {
      const dataItem = []
      initDictOptions(dic).then((res) => {
        res.data.forEach((item) => {
          dataItem.push({ text: item.text, value: item.value })
        })
      })
      return dataItem
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter((item) => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (colSettings.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    },
    //列设置更改事件
    onColSettingsChange(checkedValues) {
      var key = this.$route.name + ':colsettings'
      Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
      this.settingColumns = checkedValues
      const cols = this.defColumns.filter((item) => {
        if (item.key == 'rowIndex' || item.dataIndex == 'action') {
          return true
        }
        if (this.settingColumns.includes(item.dataIndex)) {
          return true
        }
        return false
      })
      this.columns = cols
    },

    //高级查询方法
    handleSuperQuery(arg) {
      if (!arg) {
        this.superQueryParams = ''
        this.superQueryFlag = false
      } else {
        this.superQueryFlag = true
        this.superQueryParams = JSON.stringify(arg)
      }
      this.loadData()
    },
    // 获取查询条件
    getQueryParams() {
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.limit = this.ipagination.pageSize
      return filterObj(param)
    },
    initDictConfig() {},

    // 弹出窗组件
    showDemoModal() {
      this.$refs.modalCompon.modalShow()
    },
    // 点击btn获取数据
    btnGetData(tableName, title) {
      getAction(`${this.url.getColumns}`, {
        tableName: tableName,
      }).then((res) => {
        if (res.code == 0) {
          this.queryInfo = res.data.columns
          this.title = title
          this.dictOptions = res.data.dictOptions
          this.showDemoModal()
        } else {
          this.$message.warning(res.msg)
        }
      })
    },

    //筛选分组
    getGroupTag(arrList) {
      let arr = []
      var map = {},
        dest = []
      arrList.forEach((item, index) => {
        if (item.groupTag) {
          arr.push(item)
        }
      })
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i]
        if (!map[ai.groupTag]) {
          dest.push({
            groupTag: ai.groupTag,
            name: ai.groupName,
            data: [ai],
          })
          map[ai.groupTag] = ai
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j]
            if (dj.groupTag == ai.groupTag) {
              dj.data.push(ai)
              break
            }
          }
        }
      }
      this.groupTag = dest
      console.log(dest)
    },
    showLinkButton(item, record) {
      let btn = new ButtonExpHandler(item.exp, record)
      return btn.show
    },
    initButtonList() {
      getAction(`${this.url.getColumns}52916fe800d14425a6cbcc6ce23da77a`).then(
        (res) => {
          console.log('--获取自定义按钮->>', res)
          if (res.success) {
            this.code = res.data.code
            this.initCgButtonList(res.data.cgButtonList)
            this.initCgEnhanceJs(res.data.enhanceJs)
            this.getGroupTag(res.data.cgButtonList)
          } else {
            this.$message.warning(res.msg)
          }
        }
      )
    },
    initCgEnhanceJs(enhanceJs) {
      //console.log("--onlineList-js增强",enhanceJs)
      if (enhanceJs) {
        let Obj = eval('(' + enhanceJs + ')')
        this.EnhanceJS = new Obj(getAction, postAction, deleteAction)
        this.cgButtonJsHandler('created')
      } else {
        this.EnhanceJS = ''
      }
    },
    initCgButtonList(btnList) {
      let linkArr = []
      let buttonArr = []
      if (btnList && btnList.length > 0) {
        for (let i = 0; i < btnList.length; i++) {
          let temp = btnList[i]
          if (temp.buttonStyle == 'button') {
            buttonArr.push(temp)
          } else if (temp.buttonStyle == 'link') {
            linkArr.push(temp)
          }
        }
      }
      this.cgButtonLinkList = [...linkArr]
      this.cgButtonList = [...buttonArr]
      console.log('链接增强', this.cgButtonLinkList)
    },
    cgButtonJsHandler(buttonCode) {
      if (this.EnhanceJS[buttonCode]) {
        this.EnhanceJS[buttonCode](this)
      }
    },
    cgButtonActionHandler(buttonCode) {
      //处理自定义button的 需要配置该button自定义sql
      if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
        this.$message.warning('请先选中一条记录')
        return false
      }
      if (this.selectedRowKeys.length > 1) {
        this.$message.warning('请只选中一条记录')
        return false
      }
      let params = {
        formId: this.code,
        buttonCode: buttonCode,
        dataId: this.selectedRowKeys[0],
      }
      console.log('自定义按钮请求后台参数：', params)
      postAction(this.url.buttonAction, params).then((res) => {
        if (res.success) {
          this.loadData()
          this.$message.success('处理完成!')
        } else {
          this.$message.warning('处理失败!')
        }
      })
    },
    cgButtonLinkHandler(record, buttonCode, optType) {
      if (optType == 'js') {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this, record)
        }
      } else if (optType == 'action') {
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: record.id,
        }
        console.log('自定义按钮link请求后台参数：', params)
        postAction(this.url.buttonAction, params).then((res) => {
          if (res.success) {
            this.loadData()
            this.$message.success('处理完成!')
          } else {
            this.$message.warning('处理失败!')
          }
        })
      }
    },   
    async getParams() {
      // 获取查询条件
      var param = {}
      await process.userInfo().then((res) => {
        if (res.code === 0) {
          const curData = res.data
          console.log(curData)
          param.pageNo = this.ipagination.current
          param.limit = 100
          param.definitionKey = 'MQImp'
          param.uid = curData.uid
        }
      })
      return filterObj(param)
    },
    handleProcess(record) {
      //处理流程
      // console.log(record.callbackPath)     
      if (
        typeof record.callbackPath == 'string' &&
        record.callbackPath.length > 0
      ) {
        let str =  record.callbackPath     
        let path = str.substr(str.indexOf("?"),str.length - str.indexOf("?"))
        console.log(path)
        this.$router.replace('/work/mesQualityManagement/modules/MesQcQualityImproveTask_1Process' + path)
      } else {
        this.$router.replace(
          '/work/mesQualityManagement/modules/MesQcQualityImproveTask_1Process?action=complete&processInstanceId=' +
            record.processInstanceId +
            '&processDefinitionKey=MQImp'
        )
      }
    },
    getProcessingCycle(record) {
      //处理周期     
      if (record.reviewTime !== null  && record.checkTime !== null && record.isCloseFile == 1) {
        let create_time = dayjs(record.createTime).format('YYYY-MM-DD')
        let check_time = dayjs(record.checkTime).format('YYYY-MM-DD')        
        let time = dayjs(check_time).diff(dayjs(create_time), 'day')
        return time
      } else {
        let create_time = dayjs(record.createTime).format('YYYY-MM-DD')         
        let time = dayjs().diff(dayjs(create_time), 'day')
        return time
      }
    },
    getReplyOverdue(record) {
      //超期天数
      if (record.reviewTime !== null) {
        let _reviewTime = dayjs(record.reviewTime).format('YYYY-MM-DD')
        let _nrpReplytime = dayjs(record.nrpReplytime).format('YYYY-MM-DD')
        let time = dayjs(_reviewTime).diff(dayjs(_nrpReplytime), 'day')
        if (time <= 0 ){
          time = ''
        }
        return time
      } else {
        return ''
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
